package controller

import (
	"github.com/gin-gonic/gin"
	"niu-video/app/model"
	"niu-video/app/service"
	"niu-video/pkg/response"
	"niu-video/pkg/validate"
	"strconv"
)

type CommentController struct {
}

// Login 登录
func (ctrl *CommentController) Create(c *gin.Context) {

	request := model.CommentDto{}
	if ok := validate.Validate(c, &request); !ok {
		return
	}
	userId := c.GetInt64("current_user_id")
	err := service.CommentService.Create(request, userId)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithMessage("评论成功！", c)
}

func (ctrl *CommentController) Delete(c *gin.Context) {

	request := model.DeleteCommentDto{}
	if ok := validate.Validate(c, &request); !ok {
		return
	}
	service.CommentService.Delete(request.CommentID, request.VideoID)
	response.OkWithMessage("评论已删除", c)
}

// GetCommentList 获取评论列表
func (ctrl *CommentController) GetCommentList(c *gin.Context) {
	videoId_ := c.Query("videoId")
	videoId, err := strconv.ParseInt(videoId_, 10, 64)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	vos, err := service.CommentService.GetCommentList(videoId)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(vos, c)
}
